package com.jrx.anytxn.transaction.service;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.customer.dto.customer.CustomerRes;
import com.jrx.anytxn.customer.entity.CmCustomerBankcardInfo;
import com.jrx.anytxn.i18n.response.TxnPage;
import com.jrx.anytxn.param.entity.PrAutoPaymentTable;
import com.jrx.anytxn.param.entity.PrProductTable;
import com.jrx.anytxn.transaction.dto.common.CommonReq;
import com.jrx.anytxn.transaction.dto.transactionLog.TlPaymentLogRes;
import com.jrx.anytxn.transaction.entity.BtAutoPaymentList;
import com.jrx.anytxn.transaction.entity.TlPaymentLog;
import com.jrx.anytxn.transaction.entity.TlPaymentMapping;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 还款流水service
 *
 * @author : zhenghaopu
 * 2019/10/21
 */
public interface IPaymentLogService {

    /**
     * 构建还款流水
     *
     * @param paymentType 还款类型
     * @param bank 银行卡信息
     * @param customerRes 客户信息
     *
     * @param debtAmount 还款额
     * @param businessDate 业务日期
     * @param product 产品
     * @param req 产品
     * @return 还款流水
     */
    TlPaymentLog buildTlPaymentLog(String paymentType, CmCustomerBankcardInfo bank,
                                   CustomerRes customerRes, BigDecimal debtAmount, Date businessDate, PrProductTable product, CommonReq req) throws TxnBizException;

    /**
     * 构建还款流水与订单映射信息
     *
     * @param customerId 客户id
     * @param paymentSeqNo 还款流水
     * @param loanId 订单id
     * @param tenantId 租户id
     * @return 还款流水与订单映射信息
     */
    TlPaymentMapping buildTlPaymentMapping(String customerId, String paymentSeqNo, String loanId, String tenantId) throws TxnBizException;

    /**
     * 调用网关支付，并返回更新
     * @param log
     * @return
     */
    TlPaymentLog pay(TlPaymentLog log) throws Exception;

    /**
     * 根据以下条件查询客服模板还款流水信息
     * @author fan.yang
     * date: 2020/7/30 0030 下午 16:03
     * @param channel 渠道
     * @param customerId 客户ID
     * @param tenantId 租户ID
     * @param pageNum 页码
     * @param pageSize 页大小
     * @param seqNo 流水号
     * @param beginDate 发起开始时间
     * @param endDate 发起结束时间
     * @return com.jrx.anytxn.i18n.response.TxnPage<com.jrx.anytxn.transaction.dto.transactionLog.TlPaymentLogRes>
     */
    TxnPage<TlPaymentLogRes> getPaymentWithPage(String channel, String customerId, String tenantId, Integer pageNum, Integer pageSize, String seqNo, String beginDate, String endDate);

    /**
     * 根据以下条件查询还款流水表信息
     * @author fan.yang
     * date: 2020/7/30 0030 下午 16:02
     * @param tenantId 租户ID
     * @param seqNo 流水号
     * @param customerId 客户ID
     * @return com.jrx.anytxn.transaction.dto.transactionLog.TlPaymentLogRes
     */
    TlPaymentLogRes getPaymentBySeqNoAndCusId(String tenantId, String seqNo, String customerId);

    /**
     * 获取上次批扣失败客户本次批扣金额
     * @author yhy
     * @date 2023/04/26
     * @param prAutoPaymentTable 渠道产品批扣配置信息
     * @param autoPaymentType 批扣次数
     * @param item  批扣初始化信息
     * @param totalDebt 扣款金额
     * @param businessDate 业务日期
     * @param tlPaymentLog 还款流水信息
     * @return TlPaymentLog 还款流水信息
     */
    TlPaymentLog getAutoPaymentAmount(PrAutoPaymentTable prAutoPaymentTable, int autoPaymentType,
                                    BtAutoPaymentList item, BigDecimal totalDebt, Date businessDate, TlPaymentLog tlPaymentLog);
}
